﻿using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;

namespace Wuliu.SDK.Core.RequestBuilder
{
    public class ToolHelp
    {
        public static string GetDigest(String plainText)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] dataHash = md5.ComputeHash(Encoding.UTF8.GetBytes(plainText));
            StringBuilder sb = new StringBuilder();
            foreach (byte b in dataHash)
            {
                sb.Append(b.ToString("x2").ToLower());
            }
            return Convert.ToBase64String(Encoding.GetEncoding("utf-8").GetBytes(sb.ToString()));
        }

        public static string getTimeStamp()
        {
            TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            string ret = string.Empty;
            ret = Convert.ToInt64(ts.TotalMilliseconds).ToString();
            return ret;
        }
    }
}
